import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select

testCase = "DBshop017商品管理管理分类前台侧边设置删除"
x="好好学习"

firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu3(firefox,'商品管理','商品属性','属性分组')
firefox.find_element_by_partial_link_text('添加属性组').click()
firefox.find_element_by_id("attribute_group_name").send_keys(x)
firefox.find_element_by_id("attribute_group_sort").clear()
firefox.find_element_by_id("attribute_group_sort").send_keys(1)
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
DBshopEnterMenu3(firefox,'商品管理','商品属性','属性')
firefox.find_element_by_partial_link_text('添加属性').click()

K = firefox.find_element_by_id("attribute_group_id")
ActionChains(firefox).move_to_element(K).perform()
Select(K).select_by_visible_text(x)

K = firefox.find_element_by_id("attribute_type")
ActionChains(firefox).move_to_element(K).perform()
Select(K).select_by_visible_text("下拉")
firefox.find_element_by_id("attribute_name").send_keys("天天向上")
firefox.find_element_by_xpath("//button").click()
firefox.find_element_by_link_text("删除").click()
time.sleep(2)
firefox.switch_to.alert.accept()

# 断言
time.sleep(3)
#断言  get_property("value") 根据元素的属性名获取属性值
shijizhi=firefox.find_element_by_xpath\
    ('/html/body/div[2]/div/div[2]/form/table/tbody/tr/td').get_attribute("value")
if shijizhi=="255": #如果预期值跟实际值相等
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
else:
    writeLog("%s 测试通过" % testCase)
firefox.quit()